import { Component, OnInit, ViewChild } from '@angular/core';
import {ModalDirective} from 'ngx-bootstrap';
import {HomeConfigService} from '../../../lib/service/admin/home-config.service';
import {adSystemApiUrl} from "../../../../config/api";

@Component({
  selector: 'app-config-list',
  templateUrl: './config-list.component.html',
  styleUrls: ['./config-list.component.scss'],
})
export class ConfigListComponent implements OnInit {

  configList;
  operateId: number;

  type: string;
  message: string;
  isShow = false;

  @ViewChild('delModal') public delModal: ModalDirective;

  constructor(private homeConfigService: HomeConfigService) { }

  ngOnInit() {
    this.getConfigList();
  }

  getConfigList() {
    this.homeConfigService.getHomeConfigList().subscribe(
      res => {
        if (res.code === 2000) {
          // alert(res.code + ',' + res.message);
          this.configList = res.data;
        } else {
          alert(res.code + ',' + res.message);
        }
      }
    );
  }

  // 删除配置
  delSite(id: number) {
    this.operateId = id;
    this.delModal.show();
  }
  delSiteSubmit() {
    this.homeConfigService.delHomeConfig(this.operateId).subscribe(
      res => {
        if (res.code === 2000) {
          this.type = 'success';
          this.message = '删除成功';
          this.isShow = true;
          this.delModal.hide();
          this.getConfigList();
        } else {
          this.type = 'error';
          this.message = res.message;
          this.isShow = true;
        }
      }
    )
  }

  // 备份，待有分页
  // pageChanged(event: any): void {
  //   this.getArticleList(event.page, event.itemsPerPage)
  // }
}
